package com.lagou.hw1;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class IntegerMapper extends Mapper<LongWritable, Text,IntWritable, NullWritable> {
    //准备key输出的对象,IntWritable内部默认就是升序排序，所以key用IntWritable类型
    IntWritable keyout = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //把读到的数据转成int类型
        int number = Integer.parseInt(value.toString());
        //设置IntWritable的值
        keyout.set(number);
        //把mapper的输出写入上下文
        context.write(keyout,NullWritable.get());
    }
}
